package com.quanquan.store.shenxinpay;

import java.text.SimpleDateFormat;

import java.util.HashMap;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.quanquan.store.shenxinpay.enitiy.request.InstpayRequest;
import com.quanquan.store.shenxinpay.enitiy.response.InstpayResponse;
import com.quanquan.store.shenxinpay.utils.Request;

public class ShenXinPay {

	private String baseUrl = "http://xgepay.ixpay.cn/";
	private String merId = "88000001";
	private String merTid = "00000000";
	private String redirectUri = "";
	private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyyMMdd");
	private SimpleDateFormat timeFormat = new SimpleDateFormat("HHmmss");
	private SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
	
	
	public String instpay(String orderNum,String totalAmount,String openid,String appid,String parkInfo){
		InstpayRequest request=new InstpayRequest();
		request.setAddtBusiInfo(parkInfo);
		request.setChnlType("");
		request.setIpAddr("127.0.0.1");
		request.setInstId("0000");
		request.setMerOrderId(orderNum);
		request.setMid(merId);
		request.setNotifyUrl("");
		request.setSign("");
		request.setSubAppId(appid);
		request.setSubOpenId(openid);
		request.setTid(merTid);
		request.setTotalAmount(totalAmount);
		
		String url = new StringBuffer().append(baseUrl).append("api/xlpay/instpay").toString();
		String result = Request.postJson(url, request);
		
		InstpayResponse instpay=JSON.parseObject(result, InstpayResponse.class);
		if("0000".equals(instpay.getRespCode())){
			return instpay.getChannelJSContent();
		}
		return null;
	}


	public String alipay(String orderNum,String totalAmount,String userid,String parkInfo){
		InstpayRequest request=new InstpayRequest();
		request.setMiniAppType("ALIPAY");
		request.setAddtBusiInfo(parkInfo);
		request.setChnlType("ALIPAY");
		request.setIpAddr("127.0.0.1");
		request.setInstId("0000");
		request.setMerOrderId(orderNum);
		request.setMid(merId);
		request.setNotifyUrl("http://47.103.122.189:8040/quanquan-store/alipay/payNotify");
		request.setSign("");
		request.setSubUserId(userid);
		request.setTid(merTid);
		request.setTotalAmount(totalAmount);

		String url = new StringBuffer().append(baseUrl).append("api/xlpay/instpay").toString();
		String result = Request.postJson(url, request);

		InstpayResponse instpay=JSON.parseObject(result, InstpayResponse.class);
		if("0000".equals(instpay.getRespCode())){
			return instpay.getChannelJSContent();
		}
		return null;
	}
	
	public static void main(String[] args) {
		ShenXinPay sxp=new ShenXinPay();
		//String out=sxp.instpay("191112150000109224", "0.01", "oGFxL5HD7FyfS9lGNuf2nW6z4SF8", "wxcffd448174292531", "");


		String out=sxp.alipay("191112150000109325", "0.01", "2088702453056600", "");
		System.out.println(out);
		
	}
}
